var app = getApp()
//常量数据配置
var ConstantData = require('../../../../../common/constant_data.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    hospitalList:[],
    hospitalNameList:[],
    index:0,
    leaseTypeList: [{ "val": 0, "name": "请选择" },{ "val": 1, "name": "租出其他医院轮椅" }, { "val": 2, "name": "其他医院归位桩租出轮椅" }],
    leaseTypeNameList: ["请选择", "租出其他医院轮椅", "其他医院归位桩租出轮椅"],  
    indexType:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getHospitalList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  /**
   * 获取用户的租赁记录
   */
  getUserLeaseRecord:function(e){
    var eqId = e.detail.value.eqId;
    var phone = e.detail.value.phone;
    var leaseHospitalId = this.data.hospitalList[this.data.index].id;
    var indexType = this.data.indexType;
    console.log("--->>>lesaseHospital",leaseHospitalId,indexType);
    if (leaseHospitalId && indexType) {
      var hospitalName = this.data.hospitalNameList[this.data.index];
      wx.navigateTo({
        url: 'hospital_lease_info/hospital_lease_info?leaseHospitalId=' + leaseHospitalId + "&leaseType=" + indexType + "&hospitalName=" + hospitalName,
      })

    }else {

      wx.navigateTo({
        url: 'opt_lease/opt_lease?eqId=' + eqId + "&phone=" + phone,
      })
    }

  },

  /**
   * 表单重置
   */
  formReset: function () {
    wx.removeStorageSync('setPositionHospital');
    this.setData({
      evtType: 0,
      currentHospital: "",
      eqNums: ""
    })
  },

  getHospitalList:function(){
    var that = this;
    var list = new Array();
    list.push({"id":0,"ti_name":"请选择医院"});
    app.executeRequest(function (header) {
      wx.request({
        url: ConstantData.CONSTATNT_DATA.BASE_URL + '/lease_admin/chairactive/hospitals',
        header: header,
        success: function (res) {
          console.log("hostipal---->", res);
          if (res.data.result === 0) {
            list = list.concat(res.data.data);
            let nameList = new Array();
            for (let i = 0; i < list.length; i++) {
              nameList.push(list[i].ti_name);
            }
            console.log("------hNameList", nameList, list.length);
            that.setData({
              hospitalList: list,
              hospitalNameList: nameList
            })
          }
        }
      })
    });  
  },

  bindPickerChange:function(e) {
    this.setData({
      index: e.detail.value
    })
  },

  bindTypePickerChange:function(e) {
    this.setData({
      indexType: e.detail.value
    })
  }


})